import initial from '@stores/initial'
import { IAction } from '@stores/interface'
import langReducer from './lang'
import basicsReducer from './basics'
import userReducer from './user'
import orderReducer from './order'

export default function AppReducer(state: any, action: IAction) {
  switch (action.type) {
    case '@@INIT':
      return state.withMutations((s: any) => {
        s.set('lang', initial.get('lang'))
        s.set('basics', initial.get('basics'))
      })
    default: {
      return state.withMutations((s: any) => {
        s.set('lang', langReducer(s.get('lang'), action))
        s.set('basics', basicsReducer(s.get('basics'), action))
        s.set('user', userReducer(s.get('user'), action))
        s.set('order', orderReducer(s.get('order'), action))
      })
    }
  }
}
